package cz.proks.easyhelpdesk.gwt.ui.widget;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.DomEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;

import cz.proks.easyhelpdesk.gwt.event.HasRightArrowClickHandlers;
import cz.proks.easyhelpdesk.gwt.event.RightArrowClickEvent;


public class RightArrowHyperlinkButton extends AGraphicHyperlinkButton implements HasRightArrowClickHandlers {

    @SuppressWarnings("deprecation")
    public RightArrowHyperlinkButton() {
        super();
        
        setStyleName(getResources().style().rightarrowButton());        
        addClickHandler(new ClickHandler() {
            
            @Override
            public void onClick(ClickEvent event) {                
                event.preventDefault();                
                fireEvent(new RightArrowClickEvent());
            }
        });
    }
    
    @Override
    public void onBrowserEvent(Event event) {
        DomEvent.fireNativeEvent(event, this, this.getElement());
        
        if (DOM.eventGetType(event) == Event.ONCLICK)
            event.preventDefault();
    }
    
    @Override
    public HandlerRegistration addRightArrowClickHandler(RightArrowClickEvent.Handler handler) {
        return addHandler(handler, RightArrowClickEvent.TYPE);
    }
}
